import { useState, useEffect } from 'react';

import store from '../redux/store';

import { findCinemas } from '@/api/MaiZuo';

const useCinema = () => {
  const [list, setList] = useState([]);

  let { id, name } = store.getState().CityReducer.city;

  const [cityId] = useState(id);
  const [cityName] = useState(name);

  useEffect(() => {
    findCinemas(cityId).then((res) => {
      setList(res.cinemas);
    });
    return () => {};
  }, [cityId]);

  return {
    list,
    cityName,
  };
};

export { useCinema };
